Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PhpUnitBridge] Url encoded deprecations helper config #29211

Merged

Conversation

greg0ire
Copy link
Contributor

@greg0ire greg0ire commented Nov 13, 2018

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #28048
License MIT
Doc PR symfony/symfony-docs#10701

First stab at implementing a new way of configuring the deprecation error handler. Includes a refactoring to keep things manageable.

Rework of #24867, blocked by #29718

TODO:

  • make the code 5.5 compatible 😢
  • add more tests
  • deprecate modes (using echo :P)
  • test this on real life projects and add some screenshots
  • docs PR
  • handle strict
  • adapt existing CI config

Quiet configuration

quiet

Default configuration

verbose

@greg0ire greg0ire force-pushed the url_encoded_deprecations_helper_config branch 2 times, most recently from 308d9b0 to 586053a Compare November 13, 2018 22:41
@nicolas-grekas nicolas-grekas added this to the next milestone Nov 14, 2018
@greg0ire greg0ire force-pushed the url_encoded_deprecations_helper_config branch 6 times, most recently from d010f02 to 4c7adb1 Compare November 24, 2018 13:37
@ostrolucky
Copy link
Contributor

make the code 5.5 compatible cry

Why when you are targetting master?

@greg0ire
Copy link
Contributor Author

IIRC that's because recent versions of the bridge will be used to test old versions of other Symfony components:

"php": ">=5.3.3 EVEN ON LATEST SYMFONY VERSIONS TO ALLOW USING",
"php": "THIS BRIDGE WHEN TESTING LOWEST SYMFONY VERSIONS.",
"php": ">=5.3.3"

@greg0ire
Copy link
Contributor Author

Wait @nicolas-grekas , is it really 5.3, not 5.5? Did you maybe tell me we could bump to 5.5?

@nicolas-grekas
Copy link
Member

5.5 will be good soon because 2.8 will be out of maintenance in 1 week.
We'll have to bump that 5.3 in Symfony 4.3

@greg0ire greg0ire force-pushed the url_encoded_deprecations_helper_config branch 6 times, most recently from eea83c2 to 9c62a77 Compare November 25, 2018 17:02
@greg0ire
Copy link
Contributor Author

greg0ire commented Nov 25, 2018

Here is how the "Improve stack trace display" commit changes things:

Before

#0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler::Symfony\Bridge\PhpUnit\{closure}(16384, 'The Sonata\\Core...', '/home/greg/dev/...', 17, Array)
#1 /home/greg/dev/SonataAdminBundle/vendor/sonata-project/core-bundle/src/Model/Adapter/AdapterInterface.php(17): trigger_error('The Sonata\\Core...', 16384)
#2 /home/greg/dev/SonataAdminBundle/vendor/composer/ClassLoader.php(444): include('/home/greg/dev/...')
#3 /home/greg/dev/SonataAdminBundle/vendor/composer/ClassLoader.php(322): Composer\Autoload\includeFile('/home/greg/dev/...')
#4 [internal function]: Composer\Autoload\ClassLoader->loadClass('Sonata\\CoreBund...')
#5 /home/greg/dev/SonataAdminBundle/tests/Admin/AdminTest.php(1817): spl_autoload_call('Sonata\\CoreBund...')
#6 [internal function]: Sonata\AdminBundle\Tests\Admin\AdminTest->provideGetSubject()
#7 phar:///home/greg/bin/phpunit/phpunit/Util/Test.php(856): ReflectionMethod->invoke(Object(Sonata\AdminBundle\Tests\Admin\AdminTest))
#8 phar:///home/greg/bin/phpunit/phpunit/Util/Test.php(410): PHPUnit\Util\Test::getDataFromDataProviderAnnotation('/**\n     * @dat...', 'Sonata\\AdminBun...', 'testGetSubjectF...')
#9 phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(157): PHPUnit\Util\Test::getProvidedData('Sonata\\AdminBun...', 'testGetSubjectF...')
#10 phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(906): PHPUnit\Framework\TestSuite::createTest(Object(ReflectionClass), 'testGetSubjectF...')
#11 phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(397): PHPUnit\Framework\TestSuite->addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#12 phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(511): PHPUnit\Framework\TestSuite->__construct(Object(ReflectionClass))
#13 phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(592): PHPUnit\Framework\TestSuite->addTestSuite(Object(ReflectionClass))
#14 phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(618): PHPUnit\Framework\TestSuite->addTestFile('/home/greg/dev/...')
#15 phar:///home/greg/bin/phpunit/phpunit/Util/Configuration.php(1139): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#16 phar:///home/greg/bin/phpunit/phpunit/Util/Configuration.php(988): PHPUnit\Util\Configuration->getTestSuite(Object(DOMElement), Array)
#17 phar:///home/greg/bin/phpunit/phpunit/TextUI/Command.php(889): PHPUnit\Util\Configuration->getTestSuiteConfiguration('')
#18 phar:///home/greg/bin/phpunit/phpunit/TextUI/Command.php(170): PHPUnit\TextUI\Command->handleArguments(Array)
#19 phar:///home/greg/bin/phpunit/phpunit/TextUI/Command.php(159): PHPUnit\TextUI\Command->run(Array, true)
#20 /home/greg/bin/phpunit(595): PHPUnit\TextUI\Command::main()
#21 {main}

After:

#0 [internal function] Symfony\Bridge\PhpUnit\DeprecationErrorHandler::Symfony\Bridge\PhpUnit\{closure}(16384, 'The Sonata\Core…', '/home/greg/dev/…', 17, Array)
#1 [sonata-project/core-bundle] /home/greg/dev/SonataAdminBundle/vendor/sonata-project/core-bundle/src/Model/Adapter/AdapterInterface.php(17): ::trigger_error('The Sonata\Core…', 16384)
#2 [composer] /home/greg/dev/SonataAdminBundle/vendor/composer/ClassLoader.php(444): ::include('/home/greg/dev/…')
#3 [composer] /home/greg/dev/SonataAdminBundle/vendor/composer/ClassLoader.php(322): ::Composer\Autoload\includeFile('/home/greg/dev/…')
#4 [internal function] Composer\Autoload\ClassLoader::loadClass('Sonata\CoreBund…')
#5 [source code] /home/greg/dev/SonataAdminBundle/tests/Admin/AdminTest.php(1817): ::spl_autoload_call('Sonata\CoreBund…')
#6 [internal function] Sonata\AdminBundle\Tests\Admin\AdminTest::provideGetSubject()
#7 [unknown] phar:///home/greg/bin/phpunit/phpunit/Util/Test.php(856): ReflectionMethod::invoke(Object(Sonata\AdminBundle\Tests\Admin\AdminTest))
#8 [unknown] phar:///home/greg/bin/phpunit/phpunit/Util/Test.php(410): PHPUnit\Util\Test::getDataFromDataProviderAnnotation('/**\n     * @dat…', 'Sonata\AdminBun…', 'testGetSubjectF…')
#9 [unknown] phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(157): PHPUnit\Util\Test::getProvidedData('Sonata\AdminBun…', 'testGetSubjectF…')
#10 [unknown] phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(906): PHPUnit\Framework\TestSuite::createTest(Object(ReflectionClass), 'testGetSubjectF…')
#11 [unknown] phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(397): PHPUnit\Framework\TestSuite::addTestMethod(Object(ReflectionClass), Object(ReflectionMethod))
#12 [unknown] phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(511): PHPUnit\Framework\TestSuite::__construct(Object(ReflectionClass))
#13 [unknown] phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(592): PHPUnit\Framework\TestSuite::addTestSuite(Object(ReflectionClass))
#14 [unknown] phar:///home/greg/bin/phpunit/phpunit/Framework/TestSuite.php(618): PHPUnit\Framework\TestSuite::addTestFile('/home/greg/dev/…')
#15 [unknown] phar:///home/greg/bin/phpunit/phpunit/Util/Configuration.php(1139): PHPUnit\Framework\TestSuite::addTestFiles(Array)
#16 [unknown] phar:///home/greg/bin/phpunit/phpunit/Util/Configuration.php(988): PHPUnit\Util\Configuration::getTestSuite(Object(DOMElement), Array)
#17 [unknown] phar:///home/greg/bin/phpunit/phpunit/TextUI/Command.php(889): PHPUnit\Util\Configuration::getTestSuiteConfiguration('…')
#18 [unknown] phar:///home/greg/bin/phpunit/phpunit/TextUI/Command.php(170): PHPUnit\TextUI\Command::handleArguments(Array)
#19 [unknown] phar:///home/greg/bin/phpunit/phpunit/TextUI/Command.php(159): PHPUnit\TextUI\Command::run(Array, true)
#20 [source code] /home/greg/bin/phpunit(595): PHPUnit\TextUI\Command::main()

The package name is now included, which helps me. Tell me if you do not like it, and I will remove it just before this is merged.

@greg0ire greg0ire force-pushed the url_encoded_deprecations_helper_config branch from 9c62a77 to 14fd0e1 Compare November 25, 2018 17:14
@greg0ire greg0ire force-pushed the url_encoded_deprecations_helper_config branch 8 times, most recently from 9251b1a to 1006b12 Compare April 11, 2019 20:55
@greg0ire greg0ire force-pushed the url_encoded_deprecations_helper_config branch from 1006b12 to 1c73f9c Compare April 11, 2019 21:11
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks! This will improve a lot the semantics and the flexibility!

@fabpot
Copy link
Member

fabpot commented Apr 12, 2019

Thank you @greg0ire.

@fabpot fabpot merged commit 1c73f9c into symfony:master Apr 12, 2019
fabpot added a commit that referenced this pull request Apr 12, 2019
… (greg0ire)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[PhpUnitBridge] Url encoded deprecations helper config

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #28048
| License       | MIT
| Doc PR        | symfony/symfony-docs#10701

First stab at implementing a new way of configuring the deprecation error handler. Includes a refactoring to keep things manageable.

Rework of #24867, blocked by #29718

TODO:

- [x] make the code 5.5 compatible 😢
- [x] add more tests
- [x] deprecate modes (using echo :P)
- [x] test this on real life projects and add some screenshots
- [x] docs PR
- [x] handle `strict`
- [x] adapt existing CI config

# Quiet configuration

![quiet](https://user-images.githubusercontent.com/657779/49341318-fa78c900-f64b-11e8-9504-a8a9eac4baf8.png)

# Default configuration

![verbose](https://user-images.githubusercontent.com/657779/49341322-10868980-f64c-11e8-9d90-dc3f6a18c335.png)

Commits
-------

1c73f9c [PhpUnitBridge] Url encoded deprecations helper config
return false !== strpos($key, 'Count') && false === strpos($key, 'legacy');
}, ARRAY_FILTER_USE_KEY);

if (array_sum($deprecationCounts) > $this->thresholds['total']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is broken if there is no such threshold

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is always initialized to 999999, see the ctor

return false;
}
foreach (['self', 'direct', 'indirect'] as $deprecationType) {
if ($deprecationCounts['remaining '.$deprecationType.'Count'] > $this->thresholds[$deprecationType]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is broken if there is no such threshold

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@greg0ire greg0ire deleted the url_encoded_deprecations_helper_config branch April 12, 2019 11:41
nicolas-grekas added a commit that referenced this pull request Apr 12, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

[PhpUnitBridge] fixes

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Fixes @stof's review in #29211 + fixes PHP5.5 support (array consts are PHP5.6+)
/cc @greg0ire

Commits
-------

b11585e [PhpUnitBridge] fixes
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
$ErrorHandler = self::$utilPrefix.'ErrorHandler';

return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
}

$trace = debug_backtrace();
$deprecation = new Deprecation($msg, debug_backtrace(), $file);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$msg is unserialized in Deprecation constructor but unserialized message is not used by DeprecationErrorHandler. Tried to fix it in #31382

nicolas-grekas added a commit that referenced this pull request May 5, 2019
…nErrorHandler refacto (l-vo)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[PhpunitBridge] Fix not unserialized logs after DeprecationErrorHandler refacto

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

During the refactoring for #29211 , it seems a little bug was introduced. When using runInSeparateProcess, deprecation message isn't unserialized anymore.

Commits
-------

f522729 [PhpunitBridge] Fix not unserialized logs after DeprecationErrorHandler refactoring
@fabpot fabpot mentioned this pull request May 9, 2019
}

return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg0ire what is the goal of this method please ? Is it only used for the color of the deprecation text or I missed another usage ? I saw some minors problems (see #31478 (WIP)). When using runInSeparateProcess, it's not the correct stack trace that is used to determine isIndirect result. I'm not sure how fix it. In some cases, I will not be able to serialize the deprecation original stack trace (when there is a closure). What would be (from your point of view) the consequences if isIndirect can't be determined ?

Copy link
Contributor Author

@greg0ire greg0ire May 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to help making a difference between direct and indirect. If the result is inaccurate, a test suite might fail when it should not and vice versa. I'm on hols, and answering from my phone while walking in the street so my answer might be inaccurate too :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC there is a group of "others" deprecations, maybe we should throw an exception when unable to answer, and catch it and then put the deprecation in that group

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought too about this kind of solution. To accept to not be able to determine direct/indirect in some edge cases (runInSeparateProcess and unserializable trace in this case). Thank you for your help 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See implementation of this kind of solution here: #31730

javiereguiluz pushed a commit to symfony/symfony-docs that referenced this pull request May 31, 2019
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request May 31, 2019
…ire, llaakkkk)

This PR was submitted for the master branch but it was merged into the 4.3 branch instead (closes #11323).

Discussion
----------

Document changes in the deprecation error handler

See symfony/symfony#29211
See symfony/symfony#28048

Closes #10701

Commits
-------

64141fc fixup! Document changes in the deprecation error handler
dd7eb0b fixup! Document changes in the deprecation error handler
b2a7744 fixup! Document changes in the deprecation error handler
988badf fixup! Document changes in the deprecation error handler
2a750ea Document changes in the deprecation error handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants